package com.plattysoft.leonids;

import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.render.Canvas;
import ohos.app.Context;

import java.util.ArrayList;

class ParticleField extends Component implements Component.DrawTask {

    private ArrayList<Particle> mParticles;

    public ParticleField(Context context, AttrSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        addDrawTask(this);
    }

    public ParticleField(Context context, AttrSet attrs) {
        super(context, attrs);
        addDrawTask(this);
    }

    public ParticleField(Context context) {
        super(context);
        addDrawTask(this);
    }

    public void setParticles(ArrayList<Particle> particles) {
        mParticles = particles;
    }

    @Override
    public void onDraw(Component component, Canvas canvas) {
        synchronized (mParticles) {
            for (int i = 0; i < mParticles.size(); i++) {
                mParticles.get(i).draw(canvas);
            }
        }
    }
}
